#ifndef BAROHANDLER_H
#define BAROHANDLER_H


#include <QObject>
#include <i2chandler.h>
#include <sleeper.h>
#include <qmath.h>
#include <QTimer>

#define BMP085_ADDRESS 0x77 // I2C address of BMP085

#include <QThread>
#include <QMutex>

class BaroHandler : public QObject {
    Q_OBJECT
public:
    explicit BaroHandler(QObject *parent = 0);
    short bmp085GetTemperature(bool *ok);
    long bmp085GetPressure(bool *ok);
    int getTemperature();
    int getPressure();
    float getAltitude();
    float getAverageAltitude();
public slots:
    void runHandler();
    void setReference();
private:
    int bmp085ReadInt(unsigned char address, bool *ok=0);
    void bmp085Calibration();
    int bmp085ReadUT(bool *ok=0);
    long bmp085ReadUP(bool *ok=0);
    float averageFromList(QList<float> input);
    QList<float> altitudeData;

    static const unsigned char OSS = 3;
    I2CHandler barocom;
    int pressure;
    int temperature;
    int referenceTemp;
    int referencePress;
    int ac1;
    int ac2;
    int ac3;
    int ac4;
    int ac5;
    int ac6;
    int b1;
    int b2;
    int mb;
    int mc;
    int md;
    bool referenceSet;
    bool firsttimedone;
    long b5;

    QMutex mutex;
};

#endif // BAROHANDLER_H

